#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef double db;
typedef unsigned long long ull;

#define in read()
#define pii pair<int,int>
#define fi first
#define se second
#define FILE(x) freopen(x".in","r",stdin);\
	freopen(x".out","w",stdout);
#define pb push_back

int read(){
	int x = 0,sgn = 1;char ch = getchar();
	for(;!isdigit(ch);ch = getchar()) if(ch == '-') sgn = -1;
	for(;isdigit(ch);ch = getchar()) x = (x<<1)+(x<<3)+(ch^48);
	return x*sgn;
}

const int N = 55;
const int bas = 13331;
const int mod = 19491001;

int n[N],m,x;
vector<int> G[N];
ull h[N][N],f[N],tmp[N];

void dfs(int x,int p){
	f[x] = 1;
	for(int y : G[x]) if(y != p) dfs(y,x);
	int tot = 0;
	for(int y : G[x]){
		if(y == p) continue;
		tmp[++tot] = f[y];
	}
	sort(tmp+1,tmp+tot+1);
	for(int i = 1;i <= tot;i++) f[x] = (f[x] * bas + tmp[i]) % mod;
}

int main (){
#ifndef ONLINE_JUDGE
	freopen("1.in","r",stdin);
#endif
	m = in;
	for(int i = 1;i <= m;i++){
		n[i] = in; for(int j = 1;j <= n[i];j++) G[j].clear();
		for(int j = 1;j <= n[i];j++){
			x = in; if(x) G[x].pb(j),G[j].pb(x);
		}
		for(int j = 1;j <= n[i];j++) dfs(j,0),h[i][j] = f[j];
		sort(h[i]+1,h[i]+n[i]+1);
	}
	for(int i = 1;i <= m;i++){
		for(int j = 1;j <= i;j++){
			if(j == i) {printf("%d\n",j);break;}
			if(n[i] != n[j]) continue;
			bool f = 1;
			for(int k = 1;k <= n[i];k++) if(h[i][k] != h[j][k]) {f = 0;break;}
			if(f) {printf("%d\n",j);break;}
		}
	}
	return 0;
}

